<!--
    产品查询页面 公共插件

    参数：
    modalVisible    弹窗状态
    modalTitle      弹窗主题

    方法:
    backInfo        返回
    backResult      结构
 -->
<template>
    <div>
        <Modal
            v-model="modalVisible"
            :title="modalTitle"
            :closable="false"
            :width="1000"
        >
            <rui-page :defines="defines">
                <rui-query
                    :label-width="100"
                    ref="searchFormManage"
                    :query="queryData"
                    :query-rows="queryRows"
                >
                </rui-query>
                <rui-table
                    :defineId="'productPlanDefine'"
                    :showIndex="false"
                    :columns="planColumns"
                    @loadDatas="queryData"
                    ref-query="searchFormManage"
                    @on-selection-change="changeSelect"
                    ref="productPlanTable"
                >
                </rui-table>
            </rui-page>
            <div slot="footer">
                <Button type="text" @click="backInfo">取消</Button>
                <Button type="primary" @click="addPlan">确定</Button>
            </div>
        </Modal>
    </div>
</template>
<script>

    import productPlanDefine from "@/projects/afs-core-business/pages/product/product-plan/define/product-plan-table-define";
    import {
        queryProductUpdateList
    } from "@/projects/afs-core-business/api/afs-product/product-plan-approve/approve";

    export default {
        components: {},
        props: {
            modalTitle:{
                type:String,
                required: true,
                default: '新增'
            },
            //修改信息
            parentParam:{
                type:Object,
            },
        },
        computed: {
            defines() {
                return [
                    {
                        id: "productPlanDefine",
                        fields: productPlanDefine
                    }
                ];
            }
        },
        data() {
            return {
                modalVisible:true,
                queryRows: [
                    {
                        defineId: "productPlanDefine", span: 6, fields: ["productNumber", "productName"]
                    },
                ],
                planColumns: [
                    'productNumber', 'productName', 'status'
                ],
                selectCount:0,
            };
        },
        methods: {
            //初始化列表
            queryData(queryData) {
                queryData["condition"]["templateCategory"] = this.parentParam.templateCategory;
                queryData["condition"]["productTemplateId"] = this.parentParam.productTemplateId;
                queryProductUpdateList(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.productPlanTable.updateTableData(records, total);
                    }
                });
            },
            //初始化
            refresh() {
                let queryData = {
                    pageNumber:1,
                    pageSize:10,
                    condition:{
                        templateCategory:this.parentParam.templateCategory,
                        productTemplateId:this.parentParam.productTemplateId
                    },
                }
                queryProductUpdateList(queryData).then(res => {
                    if (res.code === "0000") {
                        let {records, total} = res.data;
                        this.$refs.productPlanTable.updateTableData(records, total);
                    }
                });
            },
            clearSelectAll() {
                this.$refs.productPlanTable.getTable().selectAll(false);
            },
            changeSelect(e) {
                this.selectList = e;
                this.selectCount = e.length;
            },
            //返回
            backInfo(){
                this.$emit('backInfo',true);
            },
            //确定
            addPlan() {
                if (this.selectCount <= 0) {
                    this.$Message.warning("您还未选择数据");
                    return;
                }
                this.$Modal.confirm({
                    title: "确认保存吗",
                    content: "您确认要保存所选的 " + this.selectCount + " 条数据?",
                    onOk: () => {
                        let ids = [];
                        this.selectList.forEach(function (e) {
                            ids.push(e.id)
                        });
                        this.$emit('backResult',ids);
                    }
                });
            },
        },
        mounted() {
        },
        created(){
            this.refresh();
        },
    };
</script>
